Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Don't throw nested exception from dtor of Mock object #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Don't throw nested exception from dtor of Mock object #207

wants to merge 1 commit into from

Conversation

rgolovanov
Copy link

Fix of #206

There is a problem happened when GMock is used with 3rdParty UT-engine based on exceptions handling.

If I enables throwing exceptions from GMock: ::testing::GTEST_FLAG(throw_on_failure) = true
Then in test case if I created a local Mock object with invalid expectation call then I will get exception in exception:

Because of invalid arguments passed to the method.
During stack unwinding we will destroy Mock object and will call VerifyAndClearExpectationsLocked(); from~FunctionMockerBase()
These behavior obviously leads to process termination.

The suggestion is to check whether we already in unhandled exception or not before Verifing expectations in destructor:

    if (!std::uncaught_exception())
    {
       VerifyAndClearExpectationsLocked();
    }
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@rgolovanov
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@hendrics
Copy link

I think the project was moved inside googletest. I am sure this is not the latest version.

@rgolovanov
Copy link
Author

Yes, I found it a bit later and created pull request there too: google/googletest#1098

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants